﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace EHTSaleManager.UICustomer
{
    public partial class CustomerChangePassword : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        private Boolean ValidateData()
        {
            String message = "";
            Boolean isSuccess = true;

            if (this.txtCurrentPassword.Text.Trim().Length < 6)
            {
                message += "Current Password must have lengh > 6 <br />";
                isSuccess = false;
            }

            if (this.txtNewPassword.Text.Trim().Length < 6)
            {
                message += "New Password must have lengh > 6  <br />";
                isSuccess = false;
            }

            if (!isSuccess)
                ltrMessage.Text = message;

            return isSuccess;
        }

        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            if (!ValidateData())
                return;

            Page.Validate();

            if (Page.IsValid)
            {
                MembershipUser theUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
                if (theUser.ChangePassword(this.txtCurrentPassword.Text, this.txtNewPassword.Text))
                {
                    ltrMessage.Text = "Change password is success";
                }
                else
                {
                    ltrMessage.Text = "Current password not right";
                }

            }
        }
    }
}